package com.test.dababy.dababybean

import com.google.gson.Gson
import com.test.dababy.dababy_00_analytics.DababyUtil.DababyAnalyticsUtil
import com.test.dababy.dababy_00_utils.DababyConfigs
import com.test.dababy.dababy_00_utils.DababyUtil
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody

open class PamdababyBase(

    var path: String = "",
    var aduid: String = "",
    var androidId: String = "",
    var token: String = "",
    var isLimitAdTrackingEnabled: String = "",
    var apiVersion: String = "v3",
    var userId: String = "",
    var product: String = "",
    var aduidPath: String = "",
    var advertId: String = "",
    var version: String = "",
    var clientType: String = ""

) {
    init {

        this.userId = DababyUtil.getUserId_dababy()
        this.aduidPath = DababyAnalyticsUtil.getAndroidId_dababy()
        this.aduid = DababyAnalyticsUtil.getAdId_dababy()
        this.androidId = DababyAnalyticsUtil.getAndroidId_dababy()
        this.clientType = "ANDROID"
        this.version = DababyConfigs.dababyVERSION
        this.advertId = DababyAnalyticsUtil.getAdId_dababy()
        this.isLimitAdTrackingEnabled = DababyAnalyticsUtil.getAdEnabled_dababy().toString()
        this.token = DababyUtil.getToken_dababy()
        this.product = DababyConfigs.dababyProduct

    }

    open fun toEncryptParams(path1: String): String {
        val path2 = path1.replace("/".toRegex(), "")
        path = path2
        val content = Gson().toJson(this).trim()
        return DababyUtil.encryptDefault_dababy(content)
    }

    open fun toRequestBody(path: String): RequestBody {
        val encrypted: String = toEncryptParams(path)
        val mediaType = "text/plain".toMediaTypeOrNull()
        return encrypted.toRequestBody(mediaType)
    }
}